//
// Created by Administrator on 2021/9/2.
// sbm file define
//

#ifndef OPENGLLEARN_SBM_H
#define OPENGLLEARN_SBM_H

#define SBM_FOURCC(a, b, c, d) \
(((unsigned int)(a) << 0) | ((unsigned int)(b) << 8) | ((unsigned int)(c) << 16) | ((unsigned int)(d) << 24))

#define SBM_MAGIC \
SBM_FOURCC('S', 'B', '6', 'M')

enum SBM_CHUNK_TYPE
{
    SBM_CHUNK_TYPE_INDEX_DATA = SBM_FOURCC('I', 'N', 'D', 'X'),
    SBM_CHUNK_TYPE_VERTEX_DATA = SBM_FOURCC('V', 'R', 'T', 'X'),
    SBM_CHUNK_TYPE_VERTEX_ATTRIBS = SBM_FOURCC('A','T','R','B'),
    SBM_CHUNK_TYPE_SUB_OBJECT_LIST = SBM_FOURCC('O', 'L', 'S', 'T'),
    SBM_CHUNK_TYPE_COMMENT = SBM_FOURCC('C', 'M', 'N', 'T'),
    SBM_CHUNK_TYPE_DATA = SBM_FOURCC('D', 'A', 'T', 'A')
};

struct SBM_HEADER
{
    union
    {
        unsigned int magic;
        char magicName[4];
    };
    unsigned int size;
    unsigned int numChunks;
    unsigned int flags;
};

struct SBM_CHUNK_HEADER
{
    union
    {
        unsigned int type;
        char name[4];
    };
    unsigned int size;
};

struct SBM_CHUNK_INDEX_DATA
{
    SBM_CHUNK_HEADER header;
    unsigned int type;
    unsigned int count;
    unsigned int dataOffset;
};

struct SBM_CHUNK_VERTEX_DATA
{
    SBM_CHUNK_HEADER header;
    unsigned int size;
    unsigned int offset;
    unsigned int totalVertices;
};

struct SBM_VERTEX_ATTRIB_DECL
{
    char name[64];
    unsigned int size;
    unsigned int type;
    unsigned int stride;
    unsigned int flags;
    unsigned int dataOffset;
};

#define SBM_VERTEX_ATTRIB_FLAG_NORMALIZED 0x00000001
#define SBM_VERTEX_ATTRIB_FLAG_INTEGER 0x00000002

struct SBM_VERTEX_ATTRIB_CHUNK
{
    SBM_CHUNK_HEADER header;
    unsigned int count;
    SBM_VERTEX_ATTRIB_DECL data[1];
};

enum SBM_DATA_ENCODING
{
    SBM_DATA_ENCODING_RAW = 0
};

struct SBM_DATA_CHUNK
{
    SBM_CHUNK_HEADER header;
    unsigned int encoding;
    unsigned int offset;
    unsigned int dataLength;
};

struct SBM_SUB_OBJECT_DECL
{
    unsigned int first;
    unsigned int count;
};

struct SBM_CHUNK_SUB_OBJECT_LIST
{
    SBM_CHUNK_HEADER header;
    unsigned int count;
    SBM_SUB_OBJECT_DECL subObject[1];
};

struct SBM_CHUNK_COMMENT
{
    SBM_CHUNK_HEADER header;
    char comment[1];
};

#endif //OPENGLLEARN_SBM_H
